package com.ruoyi.recipes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.recipes.domain.Recipes;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recipes.domain.SceneTags;
import com.ruoyi.recipes.service.ISceneTagsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 食谱场景标签Controller
 * 
 * @author ruoyi
 * @date 2025-08-15
 */
@RestController
@RequestMapping("/recipes/tags")
public class SceneTagsController extends BaseController
{
    @Autowired
    private ISceneTagsService sceneTagsService;

    /**
     * 查询食谱场景标签列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:list')")
    @GetMapping("/list")
    public TableDataInfo list(SceneTags sceneTags)
    {
        startPage();
        List<SceneTags> list = sceneTagsService.selectSceneTagsList(sceneTags);
        return getDataTable(list);
    }

    /**
     * 导出食谱场景标签列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:export')")
    @Log(title = "食谱场景标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SceneTags sceneTags)
    {
        List<SceneTags> list = sceneTagsService.selectSceneTagsList(sceneTags);
        ExcelUtil<SceneTags> util = new ExcelUtil<SceneTags>(SceneTags.class);
        util.exportExcel(response, list, "食谱场景标签数据");
    }

    /**
     * 获取食谱场景标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sceneTagsService.selectSceneTagsById(id));
    }

    /**
     * 新增食谱场景标签
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:add')")
    @Log(title = "食谱场景标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SceneTags sceneTags)
    {
        return toAjax(sceneTagsService.insertSceneTags(sceneTags));
    }

    /**
     * 修改食谱场景标签
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:edit')")
    @Log(title = "食谱场景标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SceneTags sceneTags)
    {
        return toAjax(sceneTagsService.updateSceneTags(sceneTags));
    }

    /**
     * 删除食谱场景标签
     */
    @PreAuthorize("@ss.hasPermi('recipes:tags:remove')")
    @Log(title = "食谱场景标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sceneTagsService.deleteSceneTagsByIds(ids));
    }
    /**
     * 根据标签ID查询菜谱列表
     */
    @GetMapping("/recipes/{tagId}")
    public TableDataInfo getRecipesByTagId(@PathVariable("tagId") Long tagId)
    {
        startPage();
        List<Recipes> list = sceneTagsService.selectRecipesByTagId(tagId);
        return getDataTable(list);
    }
}
